package com.fzhucc.modules.subject.rest;

import com.fzhucc.annotation.AnonymousAccess;
import com.fzhucc.annotation.Log;
import com.fzhucc.base.BaseEntity.Update;
import com.fzhucc.base.PageDTO;
import com.fzhucc.modules.subject.domain.dto.SubjectHighfieldsType3CreateDto;
import com.fzhucc.modules.subject.domain.dto.SubjectHighfieldsType3QueryCriteria;
import com.fzhucc.modules.subject.domain.dto.SubjectHighfieldsType3QueryDto;
import com.fzhucc.modules.subject.service.SubjectHighfieldsType3Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @website https://fzhucc.com
* @author yyg
* @since 2022-09-26 00:00:00
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "HUCC：县区管理")
@RequestMapping("/api/county")
public class SubjectHighfieldsType3Controller {

    private final SubjectHighfieldsType3Service subjectHighfieldsType3Service;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@hu.check('county:list')")
    public void exportSubjectHighfieldsType3(HttpServletResponse response, SubjectHighfieldsType3QueryCriteria criteria) throws IOException {
        subjectHighfieldsType3Service.download(subjectHighfieldsType3Service.queryAll(criteria), response);
    }

    @GetMapping(value = "/queryCountyType")
    @Log("查询区县级")
    @ApiOperation("查询区县级")
    @AnonymousAccess
    public PageDTO<SubjectHighfieldsType3QueryDto> querySubjectHighfieldsType3(SubjectHighfieldsType3QueryCriteria criteria, Pageable pageable){
        return subjectHighfieldsType3Service.queryAll(criteria,pageable);
    }

    @PostMapping
    @Log("新增区县级")
    @ApiOperation("新增区县级")
    @PreAuthorize("@hu.check('county:add')")
    public SubjectHighfieldsType3QueryDto createSubjectHighfieldsType3(@Validated @RequestBody SubjectHighfieldsType3CreateDto resources){
        return subjectHighfieldsType3Service.create(resources);
    }

    @PutMapping
    @Log("修改区县级")
    @ApiOperation("修改区县级")
    @PreAuthorize("@hu.check('county:edit')")
    public void updateSubjectHighfieldsType3(@Validated @Update @RequestBody SubjectHighfieldsType3CreateDto resources){
        subjectHighfieldsType3Service.update(resources);
    }

    @DeleteMapping
    @Log("删除区县级")
    @ApiOperation("删除区县级")
    @PreAuthorize("@hu.check('county:del')")
    public void deleteSubjectHighfieldsType3(@RequestBody Integer[] ids) {
        subjectHighfieldsType3Service.deleteAll(ids);
    }
}